<?php
/**
 * $Id:$
 *
 * FGS is the legal property of its developers, whose names are too numerous
 * to list here.  Please refer to the COPYRIGHT file distributed with this
 * source distribution.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

require_once('sql.class.php');
require_once('utils.class.php');
require_once('log.class.php');
require_once('lang.class.php');
require_once('news.class.php');
require_once('matchs.class.php');
require_once('games.class.php');
require_once('proxys.class.php');
require_once('stats.class.php');
require_once('users.class.php');
require_once('commands.class.php');
require_once('xmlrpc.class.php');

class fgs {

	function init($init_sql = true) {
		$GLOBALS['fgs'] = array();
		if (file_exists('config.php'))
			require_once('config.php');
		fgsLang::init();
		if ($init_sql)
			fgs::sql();
	}

	function & config($key = null, $value = null) {
		if ($key !== null && $value !== null)
			 $GLOBALS['fgs'][$key] = $value;
		else if ($key !== null)
			return $GLOBALS['fgs'][$key];
		return $GLOBALS['fgs'];
	}

	function sql($new = false) {
		static $_sql_instance = null;
		$config = fgs::config();
		if (is_null($_sql_instance) || $new)
			$_sql_instance = new fgsSql($config['db_host'], $config['db_base'], $config['db_user'], $config['db_pass']);
		return $_sql_instance;
	}

	function showConfig() {
		$config = & fgs::config();
		$w = array();
		foreach($config as $key=>$value) 
			$w[] = sprintf('	$config["%s"] = "%s";', $key, $value);
		$s = sprintf('<? 
	$config = & fgs::config();
%s
?>',
			implode("\n", $w)
		);

		return $s;
	}

	function tr() {
		return call_user_func_array(
			array('fgsLang', 'tr'),
			func_get_args()
		);
	}

}

?>
